﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Motorcade
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Default.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-08-29   Created by 杨光远 V1.00.0000
    /// 功能说明：加载车辆信息维护页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Main : Component.PageBase
    {

        #region ---基本变量实例化---
        Vehicle.BLL.Motorcade b_Motorcade = new Vehicle.BLL.Motorcade();
        BLL.Log b_Log = new Vehicle.BLL.Log();
        Vehicle.Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region ---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbtn_AllDelete.Attributes.Add("onClick", "return   confirm('您确定要删除该车队？');");
                RepeaterDataBind();//绑定数据
            }
        }
        /// <summary>
        /// 绑定页面Repeater数据
        /// </summary>
        protected void RepeaterDataBind()
        {
            //如果选择为全部则选择值为0 通用实体层匹配条件为1 结果为1  Drop_Select.SelectedValue == "0" ? "1": Drop_Select.SelectedValue
            this.Anp_Page.RecordCount = b_Motorcade.GetAllSearchCount(new Model.ComponentsInfo("Motorcade", "1", "1", "1", "1", "M_IsDelete", "1", "M_Time", Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_Start.DateString)), Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_End.DateString)), "M_ID"));//根据下拉菜单选择的进行数据绑定获得总数
            m_ComponentsInfo.startIndex = Anp_Page.StartRecordIndex;//当前页的起始索引
            m_ComponentsInfo.endIndex = Anp_Page.EndRecordIndex;//当前页的结束索引
            m_ComponentsInfo.condition = "1";//条件一
            m_ComponentsInfo.result = "1";//匹配结果一
            m_ComponentsInfo.Scondition = "M_IsDelete";//条件三
            m_ComponentsInfo.Sresult = "1";//匹配结果三
            if (Gmdp_Start.DateString != "")//判断起始时间是否为空
            {
                m_ComponentsInfo.StartTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString);
            }
            if (Gmdp_End.DateString != "")//判断结束时间是否为空
            {
                m_ComponentsInfo.EndTime = Vehicle.Common.TextHelper.StringToDateTime(Gmdp_Start.DateString);
            }
            b_Motorcade.RepeaterBind(ReptShow, m_ComponentsInfo); //绑定Repeater控件
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }

        }

        /// <summary>
        /// 根据时间选择数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }

        /// <summary>
        /// Rept绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((LinkButton)(e.Item.FindControl("Lbtn_Delete"))).Attributes.Add("onClick", "return   confirm('您确定删除该车队？');");
            }

        }
        /// <summary>
        /// Rept激发事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

            if (e.CommandName == "Delete")
            {
                b_Motorcade.AllUpdate(new Model.ComponentsInfo("Motorcade", "M_IsDelete", "1", "M_ID", e.CommandArgument.ToString()));//假删除数据
                b_Log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功删除编号为" + e.CommandArgument.ToString() + "的车队信息"));//添加日志
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
        }
        /// <summary>
        /// 全部删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtn_AllDelete_Click(object sender, EventArgs e)
        {
            int Count = 1;
            foreach (RepeaterItem item in ReptShow.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("Chk_Num");
                if (chk.Checked)
                {
                    Count++;
                    b_Motorcade.AllUpdate(new Model.ComponentsInfo("Motorcade", "M_IsDelete", "1", "M_ID", chk.ToolTip));//假删除数据
                    b_Log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功删除编号为" + chk.ToolTip + "的车队信息"));//添加日志
                }

            }
            if (Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('您还没有进行选择！')", true);
            }
        }

        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        #endregion
    }
}
